package com.ruoyi.points.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.points.domain.BargainGroupListSon;
import com.ruoyi.points.service.IBargainGroupListSonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.points.domain.BargainGroupListGrandson;
import com.ruoyi.points.service.IBargainGroupListGrandsonService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 412Controller
 *
 * @author ruoyi
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/grandson")
public class BargainGroupListGrandsonController extends BaseController
{
    @Autowired
    private IBargainGroupListGrandsonService bargainGroupListGrandsonService;


    @Autowired
    private IBargainGroupListSonService bargainGroupListSonService;
    /**
     * 查询412列表
     */
    @RequiresPermissions("points:grandson:list")
    @GetMapping("/list")
    public TableDataInfo list(String  id)
    {
        startPage();
        BargainGroupListGrandson bargainGroupListGrandson = new BargainGroupListGrandson();
//        获取前台传过来的id
        bargainGroupListGrandson.setId(Long.parseLong(id));
//        通过id去查询对应的子表所有数据
        List<BargainGroupListGrandson> list = bargainGroupListGrandsonService.selectBargainGroupListGrandsonList(bargainGroupListGrandson);
//        定义一个新的实时更新我们的帮助砍价人数
        BargainGroupListSon son = new BargainGroupListSon();
//        设置要更新的id
        son.setId(bargainGroupListGrandson.getId());
//        获取尺寸的操作，遍历list集合进行统计
        String  size ="";
        Integer re = 0;
        for (BargainGroupListGrandson groupListGrandson : list) {
            re++;
        }
        size=re.toString();
        son.setHelpNum(size);
//        设置数量后进行更新呢
        bargainGroupListSonService.updateBargainGroupListSon(son);
        return getDataTable(list);
    }

    /**
     * 导出412列表
     */
    @RequiresPermissions("points:grandson:export")
    @Log(title = "412", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BargainGroupListGrandson bargainGroupListGrandson)
    {
        List<BargainGroupListGrandson> list = bargainGroupListGrandsonService.selectBargainGroupListGrandsonList(bargainGroupListGrandson);
        ExcelUtil<BargainGroupListGrandson> util = new ExcelUtil<BargainGroupListGrandson>(BargainGroupListGrandson.class);
        util.exportExcel(response, list, "412数据");
    }

    /**
     * 获取412详细信息
     */
    @RequiresPermissions("points:grandson:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bargainGroupListGrandsonService.selectBargainGroupListGrandsonById(id));
    }

    /**
     * 新增412
     */
    @RequiresPermissions("points:grandson:add")
    @Log(title = "412", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BargainGroupListGrandson bargainGroupListGrandson)
    {
        return toAjax(bargainGroupListGrandsonService.insertBargainGroupListGrandson(bargainGroupListGrandson));
    }

    /**
     * 修改412
     */
    @RequiresPermissions("points:grandson:edit")
    @Log(title = "412", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BargainGroupListGrandson bargainGroupListGrandson)
    {
        return toAjax(bargainGroupListGrandsonService.updateBargainGroupListGrandson(bargainGroupListGrandson));
    }

    /**
     * 删除412
     */
    @RequiresPermissions("points:grandson:remove")
    @Log(title = "412", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bargainGroupListGrandsonService.deleteBargainGroupListGrandsonByIds(ids));
    }
}
